package org.openkoala.koala.popup;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Display;
import org.openkoala.koala.exception.KoalaException;

/**
 * 点击“删除权限管理”时运行的action
 * @author xmfang
 *
 */
@Deprecated
public class RemoveSecurityModuleAction extends SecurityModuleBaseAction {

	@Override
	public void run(IAction arg0) {
		if (!initAndVerify()) {
			return;
		}
		
		ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(
				Display.getCurrent().getActiveShell());
		try {
			monitorDialog.run(true, true, new IRunnableWithProgress() {
				@Override
				public void run(IProgressMonitor monitor) throws InvocationTargetException,
						InterruptedException {
					monitor.beginTask("删除统一认证组件...", 3);
					monitor.worked(1);
					
					monitor.setTaskName("删除统一认证组件文件及配置...");
					try {
						//SecurityUpdateParse.updateSecurity(getProject(), getModule(), null);
					} catch (KoalaException e) {
						e.printStackTrace();
					}
					monitor.worked(2);
					
					monitor.setTaskName("刷新项目...");
					try {
						getSelectedResource().refreshLocal(IResource.DEPTH_INFINITE, null);
					} catch (CoreException e) {
						e.printStackTrace();
					}
					
					monitor.worked(3);
					monitor.done();
				}
			});
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
